package com.mac.hosp_pre.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mac.hosp_pre.admin.model.req.HospitalConfigReqDto;
import com.mac.hosp_pre.admin.model.resp.HospitalConfigRespDto;
import com.mac.hosp_pre.admin.model.req.HospitalQueryReqDto;
import com.mac.hosp_pre.reply.R;
import com.mac.hosp_pre.admin.service.HospitalConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "医院配置管理")
@RestController
@RequestMapping("/admin/hosp/hospitalConfig")
public class HospitalConfigController {

    @Autowired
    private HospitalConfigService hospitalSetService;


   /* @Operation(summary = "获取所有医院配置")
    @GetMapping("findAll")
    public R findAllHospitalConfig() {
        List<HospitalConfig> list = hospitalSetService.list();
        return R.success(list);
    }*/

    @Operation(summary = "逻辑删除医院配置")
    @Parameter(name = "id", description = "医院配置id",in = ParameterIn.PATH)
    @DeleteMapping("{id}")
    public R removeHospConfig(@PathVariable Long id) {
        hospitalSetService.removeById(id);
        return R.success();
    }

    @Operation(summary = "条件查询带分页")
    @PostMapping("findPage")
    public R findPageHospConfig(@RequestBody(required = false) HospitalQueryReqDto hospitalSetQuery) {
        IPage<HospitalConfigRespDto> pageHospitalSet = hospitalSetService.findPageHospConfig(hospitalSetQuery);
        //返回结果
        return R.success(pageHospitalSet);
    }

    @Operation(summary = "添加医院配置")
    @PostMapping("add")
    public R add(@RequestBody HospitalConfigReqDto hospitalConfigReq) {
        hospitalSetService.add(hospitalConfigReq);
        return R.success();
    }

    @Operation(summary = "根据id获取医院配置")
    @Parameter(name = "id", description = "医院配置id",in = ParameterIn.PATH)
    @GetMapping("get/{id}")
    public R getHospConfig(@PathVariable Long id) {
        HospitalConfigRespDto respDto = hospitalSetService.getHospConfig(id);
        return R.success(respDto);
    }

    //6 修改医院配置
    @Operation(summary = "修改医院配置")
    @PostMapping("update")
    public R updateHospitalConfig(@RequestBody HospitalConfigReqDto hospitalSet) {
        hospitalSetService.updateHospitalConfig(hospitalSet);
        return R.success();
    }

    @Operation(summary = "批量删除医院配置")
    @PostMapping("batchRemove")
    public R batchRemoveHospitalConfig(@RequestBody List<Long> idList) {
        hospitalSetService.removeByIds(idList);
        return R.success();
    }

    @Operation(summary = "医院配置锁定和解锁")
    @Parameters({
            @Parameter(name = "id", description = "医院配置id",in = ParameterIn.PATH),
            @Parameter(name = "status", description = "状态",in = ParameterIn.PATH)
    })
    @PutMapping("lock/{id}/{status}")
    public R lockHospitalConfig(@PathVariable Long id,
                                  @PathVariable Integer status) {
        hospitalSetService.lockHospitalConfig(id,status);
        return R.success();
    }

    @Operation(summary = "发送签名秘钥")
    @Parameter(name = "id", description = "医院配置id",in = ParameterIn.PATH)
    @PutMapping("sendKey/{id}")
    public R sendKey(@PathVariable Long id) {
        hospitalSetService.sendKey(id);
        return R.success();
    }
}
